//
//  XTCellOfgeshou.m
//  TTLestening
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "XTCellOfgeshou.h"
#import "XTCellForCellOfgeshou.h"
#import "XCModelForFind.h"
#import "XCModelForHeader.h"
#import "XCCellForHeader.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width

#define WIDGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface XTCellOfgeshou ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,retain)UITableView *tableview;

@property (nonatomic, retain)XCModelForHeader *model;

@property (nonatomic, retain) NSArray *arrayForHotList;

@end

@implementation XTCellOfgeshou


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creattabview];
        
        
    }
    return self;
}


-(void)creattabview{

    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    [self.contentView addSubview:self.tableview];
    
    self.tableview.delegate =self;
    self.tableview.dataSource = self;
    
    self.tableview.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableview.scrollEnabled =NO; //设置tableview
    
    UINib *nib = [UINib nibWithNibName:@"XTCellForCellOfgeshou" bundle:[NSBundle mainBundle]];
    
    [self.tableview registerNib:nib forCellReuseIdentifier:@"pool1"];
    
    [self.tableview registerClass:[XCCellForHeader class] forHeaderFooterViewReuseIdentifier:@"tableViewHeader"];

    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 40 * HEIGHTT;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    XCCellForHeader *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"tableViewHeader"];

    [cell.buttonForMore addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell passModel:self.model];
    
    return cell;
    
}

- (void)moreAction:(UIButton *) button {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushMoreIMSinger" object:nil];

}

- (void)passModelForArray:(NSArray *)array headerModel:(XCModelForHeader *)model {
    
    self.model = model;

    self.arrayForHotList = array;
    
    [self.tableview reloadData];
    
}

-(void)layoutSubviews{
    
    
    [super layoutSubviews];
    
    self.tableview.frame = self.contentView.frame;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 3;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 0.25 * WIDTH; 
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    XTCellForCellOfgeshou *cell = [tableView dequeueReusableCellWithIdentifier:@"pool1"];
    XCModelForFind *model = [self.arrayForHotList objectAtIndex:indexPath.row];
    
    [cell passModel:model];
    
    return cell;
}

#warning 推出网页

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    XCModelForFind *model = [self.arrayForHotList objectAtIndex:indexPath.row];
    
    NSLog(@"%@",model.action);
    
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"currenTime" object:nil userInfo:@{@"current": self.curr, @"total": self.duar}];
//    
//    [cell.cirview setNeedsDisplay];
//    
//}];

    [[NSNotificationCenter defaultCenter]postNotificationName:@"geshouwebview" object:nil userInfo:@{@"value":[model.action objectForKey:@"value"]}];
    
//    

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
